------------------ fgui require start ------------------
------------------  fgui require end  ------------------
local GuildNameModifySkin = Class("GuildNameModifySkin");

function GuildNameModifySkin:ctor(com)
    ------------------ fgui事件绑定start ------------------
    self:bindChild(com);
    self.btn_blackbackground.onClick:Add(self.onTouch_Btn_blackbackground,self);
    self.btn_cancel.onClick:Add(self.onTouch_Btn_cancel,self);
    self.btn_determine.onClick:Add(self.onTouch_Btn_determine,self);
    self:init();
    ------------------  fgui事件绑定end  ------------------
end

function GuildNameModifySkin:bindChild(com)
    ------------------ fgui变量绑定start ------------------
    self.fguiObj = com;
    self.btn_blackbackground = com:GetChild("Btn_blackbackground");
    self.btn_cancel = com:GetChild("Btn_cancel");
    self.btn_determine = com:GetChild("Btn_determine");
    self.text_amendmentnotice = com:GetChild("Text_amendmentnotice");
    self.text_close = com:GetChild("Text_close");
    self.input_guildName = com:GetChild("input_guildName");
    self.text_cost = com:GetChild("Text_cost");
    ------------------  fgui变量绑定end  ------------------
end

function GuildNameModifySkin:init() 
    self.closeCallback = nil;
    self.input_guildName.text = logicMgr.GuildManager.getUnionName();
    self.input_guildName.promptText = getLanguage("GuildInvestment_1043");
    local needNum = logicMgr.GuildManager.getGuildParaIntValue(13);
    self.enough = logicMgr.ItemManager.getCurrencyCountByModelId(CurrencyEnum.GOLD) >= needNum;
    self.text_cost.text = (self.enough and "[color=#FFFFFF]"  or "[color=#FF0000]") .. needNum .. "[/color]";
    ListenEvent(Config.EventType.Union_Rename_S2C, self.respUnionRename,self);
end

function GuildNameModifySkin:OnDestroy()
    ------------------ fgui事件移除start ------------------
    self:beforeDestroy();
    self.btn_blackbackground.onClick:Clear();
    self.btn_cancel.onClick:Clear();
    self.btn_determine.onClick:Clear();
    ------------------  fgui事件移除end  ------------------
end

function GuildNameModifySkin:onTouch_Btn_blackbackground(obj) 
    if self.closeCallback then self.closeCallback() end;
end

function GuildNameModifySkin:onTouch_Btn_cancel(obj) 
    if self.closeCallback then self.closeCallback() end;
end

function GuildNameModifySkin:onTouch_Btn_determine(obj)
    local unionName = string.trim(self.input_guildName.text);
    if unionName == logicMgr.GuildManager.getUnionName() then
        if self.closeCallback then self.closeCallback() end;
    else
        if #unionName == 0 then
            UISysTips.AddMsg(getLanguage("GuildInvestment_1043"));
            return
        end

        if logicMgr.ChatManager.HasFilterBlockWord(unionName) then
            UISysTips.AddMsg(getLanguage("UIFriend_ApplyMsgBlock"))
            return;
        end

        if tonumber(unionName) then
            self.input_guildName.text = logicMgr.GuildManager.getUnionName();
            UISysTips.AddMsg(getLanguage("GuildInvestment_1070"));
            return
        end

        if not self.enough then
            UISysTips.AddMsg(getLanguage("GuildInvestment_1071"));
            return
        end

        unionHandler.reqUnionRename(string.trim(self.input_guildName.text));
    end
end

------------------  ↑ fgui事件句柄 ↑  ------------------

function GuildNameModifySkin:setCloseCallback(func,target)
    self.closeCallback = func;
end

function GuildNameModifySkin:respUnionRename()
    if self.closeCallback then 
        self.closeCallback();
    end
end

function GuildNameModifySkin:beforeDestroy() 
    self.closeCallback = nil;
    CloseEvent(Config.EventType.Union_Rename_S2C, self.respUnionRename,self);
end

return GuildNameModifySkin;
